﻿var PageManager = {};
var PagesScripts = {};

PageManager.cachedPages = [];
PageManager.TMPPageParams;
PageManager.PageParams;

PageManager.init = function () {
	$(document).bind("orientationchange", function(e){
		$(window).trigger("throttledresize");
	});

	$(window).bind("resize", function(e){
		PagesScripts.post.resizeContent();
	});	
	
    $("div[data-role='page']").live("pageshow", function (event) {
		PageManager.PageParams = [];
		PageManager.TMPPageParams = location.search;
		if (PageManager.TMPPageParams.substr(0,1) == "?") {
			PageManager.TMPPageParams = PageManager.TMPPageParams.substr(1);
		}
		PageManager.TMPPageParams = PageManager.TMPPageParams.split("&");
		for (var i=0;i<PageManager.TMPPageParams.length;i++) {
			if (PageManager.TMPPageParams[i] != "") {
				PageManager.TMPPageParams[i] = PageManager.TMPPageParams[i].split("=");
				if (PageManager.TMPPageParams[i].length == 2) {
					PageManager.PageParams[PageManager.TMPPageParams[i][0]] = PageManager.TMPPageParams[i][1];
				}
			}
		}
		if ($(event.target).attr("initFunc")) eval($(event.target).attr("initFunc"));
    });
	
    $("div[data-role='page']").live("pageinit", function (event) {
		if ($(event.target).attr("createFunc")) eval($(event.target).attr("createFunc"));
        $("*[tap]").each(function (elemIndex, elemObject) {
            $(elemObject).bind("tap", function () {
                eval($(elemObject).attr("tap"))
            });
        });

		if (Utils.isAndroid()) {
			$("div[data-role='footer']").each(function() {
				$(this).css("display","none");
			});
		}
    });
	
	for (var i=0;i<PageManager.cachedPages.length;i++) {
		//$.mobile.loadPage("pages/" + PageManager.cachedPages[i]);
	}
}

PageManager.changePage = function (pageName, params) {
	$.mobile.changePage("pages/" + pageName + ".html", params);
}

PageManager.showPopup = function (popupDIV) {}